<?php

class Application_Model_Editions extends Application_Model_Base{
    private static $instance = null;
    public static function getInstance(){
        if (null === self::$instance) self::$instance = new self();
        return self::$instance;
    }
    private function __clone() {}
    private function __construct() {}

    public function getPaginatorForFilter($params){
        //var_dump($params);
        $select = $this->getDBAdapter()->select()
            ->from('editions');
        if (!empty($params['edition_name'])){
            $select->where("`edition_name` LIKE '%{$params['edition_name']}%'");
        }
        $paginatorAdapter = new Zend_Paginator_Adapter_DbSelect($select);
        return new Zend_Paginator($paginatorAdapter);
    }

    public function getAll(){
        return $this->getDBAdapter()->query("
            select * from `editions`
        ")->fetchAll();
    }

    public function getAllForSelect(){
        $editions = $this->getDBAdapter()->query("
            select `edition_id`, `edition_name` from `editions`
        ")->fetchAll();
        $editionsForSelect = array();
        foreach($editions as $edition){
            $editionsForSelect[$edition['edition_id']] = $edition['edition_name'];
        }
        return $editionsForSelect;
    }

    public function create($data){
        $this->getDBAdapter()->insert('editions', $data);
    }
}